# This is a parent class of all channels. This class is responsible for routing the decode
# request to the appropriate concrete class
require 'Concrete2b1ChannelInterpreter'
require 'Concrete2b6ChannelInterpreter'
require 'Concrete2b7ChannelInterpreter'
require 'Concrete2c0ChannelInterpreter'
require 'Concrete2c2ChannelInterpreter'

TP_MESSAGES = ["2B1","2B6","2B7","2C0","2C2"]


class GenericChannelInterpreter

  def initialize
    @concrete_channel_interpreters = []

    @concrete_channel_interpreters.push(Concrete2b1ChannelInterpreter.new())
    @concrete_channel_interpreters.push(Concrete2b6ChannelInterpreter.new())
    @concrete_channel_interpreters.push(Concrete2b7ChannelInterpreter.new())
    @concrete_channel_interpreters.push(Concrete2c0ChannelInterpreter.new())
    @concrete_channel_interpreters.push(Concrete2c2ChannelInterpreter.new())
  end

  def process(signal_id, packet)
    puts "processing packet"
    if (TP_MESSAGES.include?(signal_id))
      # send to appropriate channel for decoding
      puts "valid packet found"
      channel_index = TP_MESSAGES.index(signal_id)
      puts "channel index of packet:"+channel_index.to_s
      packet_with_interpretation = @concrete_channel_interpreters[channel_index].process(packet)
    else
      # return the packet as it is
      packet_with_interpretation = packet
    end
    return packet_with_interpretation
  end

end
